package com.pinxiang.framework.weather.power.controller;

import com.alibaba.fastjson.JSON;
import com.pinxiang.framework.weather.power.model.NorReport;
import com.pinxiang.framework.weather.power.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/report")
public class ReportController {

    @Autowired
    private IReportService reportService;

    @RequestMapping(value = "/dataGrid")
    @ResponseBody
    public String query(String startTime, String endTime, String deviceCode, String flg, HttpServletRequest request,
                        HttpServletResponse response) {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("startTime", startTime);
        parameters.put("endTime", endTime);
        parameters.put("deviceCode", deviceCode);
        List<NorReport> list = new ArrayList<NorReport>();
        if (flg.equals("Hr_Temp_Avg")) {
            parameters.put("col", "Hr_Temp_Avg");
            list = reportService.selectByparameter(parameters);
        }


        String json = JSON.toJSONString(list);
        return json;
    }

}
